package dongshi.daddy.springioc.three.three_five.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class DatabaseCondition implements Condition  {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment env = context.getEnvironment();
        /**
         * database.driverName=com.mysql.jdbc.Driver
         * database.url=jdbc:mysql://localhost:3306:chapter3
         * database.username=root
         * database.password=123456
         * @return
         */
        return env.containsProperty("database.driverName")
                && env.containsProperty("database.url")
                && env.containsProperty("database.username")
                && env.containsProperty("database.password");
    }
}
